[pull] master from ruby:master#1006
Merged
Merged
Conversation
…6828) ## Summary `GuardType` narrows only its result id, not the original input. A later guard on the same input therefore looks unfoldable to `fold_constants` even though the side-exit semantics already prove the narrower type. Canonicalize rewrites later uses to the most recent `Guard*` result, making the redundant guard foldable. For example, in this CFG-join shape: ```ruby def test(n, cond) if cond a = n + 1 else a = n + 2 end n + a # `n` gets a redundant Fixnum guard here end ``` This PR adds a block-local HIR `canonicalize` pass that walks each block in RPO and rewrites every operand through union-find plus a per-block `rewrite_map` keyed on the most recent `Guard*` for that value. After canonicalization, `infer_types` can narrow merge-block parameter types and `fold_constants` can then drop the redundant guards in both shapes above. Inspired by Cranelift's canonicalize https://cfallin.org/blog/2026/04/09/aegraph/ Fixes: Shopify#978 ## Benchmarks Bench (arm64 linux devcontainer, ruby/ruby-bench, warmup=10 bench=20) ``` Throughput master/staged lobsters 1.021 (+2.1%, within ±3-6% noise) railsbench 1.012 (+1.2%, within ±3-4% noise) --zjit-stats lobsters / railsbench code_region_bytes -1.1% / -1.0% (redundant CFG-join guards still removed) guard_type_count -29.4% / +30.1% (railsbench likely single-run noise) ⚠ compile_hir_time +14.6% / +13.7% (canonicalize_time: 67ms / 31ms) invalidation_time ±0% / ±0% ```
…cks (#16888) * Swap conditionals so HIR -> LIR is easier We're going to give HIR regular BBs which means each block can end with up to two jump instructions. IfTrue/IfFalse will always be followed by a Jump, so when we lower to LIR this change will make the lowering more natural. We'll only have to emit a jz/jnz for the IfTrue/IfFalse cases, and the Jump instructions will be naturally handled * Convert HIR EBB to regular BB This commit converts HIR EBB to regular BB. It ensures that all basic blocks in HIR end with 1 or 2 jump instructions, and that there are no jump instructions that appear mid-block. * implement condbranch * remove num_successors (we do not need it) * oops! * oops! * Do not use clone * fix insta * remove comment * check for terminator in rpo loop * peek at next instruction for new blocks in the jit entry * add comment
Now that ece14b6 has landed, we get this for free. We will eventually add value numbering, which will do more, but for now remove this ad-hoc code.
[Bug #22064]
Compare-by-identity sets use the address for hashing, so we must pin it
so the object does not move in GC compaction. Objects in a compare-by-identity
set is not currently pinned, causing the set to be broken if the object
is moved.
For example:
set = Set.new.compare_by_identity
o = Object.new
set.add(o)
puts set.include?(o)
GC.verify_compaction_references(expand_heap: true, toward: :empty)
puts set.include?(o)
It should output true twice, but it outputs true and false.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )